﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.ActiveRecord;
using System.Data;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.OGWell.Json
{
    public partial class DJJCXX : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int page = Request.Params["page"].ToInt32();
            int pagesize = Request.Params["rows"].ToInt32();
            string sort = Request.Params["sort"].ToRequestString();
            string jh = Request.Form["jh"].ToRequestString();
            string dwbm = Request.Form["dwbm"].ToRequestString();
            string dqbm = Request.Form["dqbm"].ToRequestString();
            string cxbm = Request.Form["cxbm"].ToRequestString();
            string cyjh = Request.Form["cyjh"].ToRequestString();
            string tcrq = Request.Form["tcrq"].ToRequestString();
            string sczt = Request.Form["sczt"].ToRequestString();
            string jb = Request.Form["jb"].ToRequestString();
            string bz = Request.Form["bz"].ToRequestString();

            string strwhere = "";

            if (dwbm.Equals(""))
            {
                dwbm = Request.QueryString["dwbm"].ToRequestString();
            }

            if (!string.IsNullOrEmpty(jh))
            {
                strwhere += " and jh like '"+jh.Trim()+"%' ";
            }

            if (!string.IsNullOrEmpty(dqbm))
            {
                strwhere += " and jh = '" + dqbm.Trim() + "' ";
            }

            if (!string.IsNullOrEmpty(cxbm))
            {
                strwhere += " and cxbm = '" + cxbm.Trim() + "' ";
            }

            if (!string.IsNullOrEmpty(cyjh))
            {
                strwhere += " and cyjh = '" + cyjh.Trim() + "'";
            }

            if (!string.IsNullOrEmpty(tcrq))
            {
                strwhere += " and tcrq = '" + tcrq.Trim() + "'";
            }

            if (!string.IsNullOrEmpty(sczt))
            {
                strwhere += " and sczt = '" + sczt.Trim() + "'";
            }

            if (!string.IsNullOrEmpty(jb))
            {
                strwhere += " and jb = '" + jb.Trim() + "'";
            }

            if (!string.IsNullOrEmpty(bz))
            {
                strwhere += " and bz like '" + bz.Trim() + "%'";
            }

            Response.Clear();
            string sql = @"select a.*,b.cxmc,c.dqmc,d.qkmc,e.dwmc,a.rowid from djjcxx a,bm_cx b, bm_dq c,bm_qk d ,dwbmb e where a.dwbm=e.dwbm(+) and a.dqbm=c.dqbm(+) and a.qkbm=d.qkbm(+) and a.cxbm=b.cxbm(+) 
                                        and a.dwbm like '"+dwbm+"%' "+strwhere+
                                        "order by a.tcrq desc";
            DataTable dt = Maticsoft.DBUtility.DbHelperOra.Query(sql).Tables[0];
            string json = dt.ToJsonForGrid(page, pagesize);
            Response.Write(json);
            Response.End();
        }
    }
}